package com.tanhua.server.controller;

import com.tanhua.server.service.PeachBlossomService;
import com.tanhua.server.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: cloudy
 * @Description:
 * @Date: Created in 9:08 2021/1/17
 * @ModifiedBy:
 */
@RestController
@RequestMapping("peachblossom")
public class PeachBlossomController {

    @Autowired
    private PeachBlossomService peachBlossomService;

    @PostMapping
    public ResponseEntity<Void> sendMsg(@RequestParam("soundFile") MultipartFile soundFile) {
        try {
            Boolean bool = this.peachBlossomService.sendMsg(soundFile);
            if (bool) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    @GetMapping
    public ResponseEntity<SoundVo> getMsg() {
        try {
            SoundVo soundVo = this.peachBlossomService.getMsg();
            if (soundVo!=null){
                return ResponseEntity.ok(soundVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
